package xyz.lovegu.server.sys.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import xyz.lovegu.server.sys.common.DataGridView;
import xyz.lovegu.server.sys.common.ResultMessage;
import xyz.lovegu.server.sys.common.ResultObj;
import xyz.lovegu.server.sys.common.ResultUtil;
import xyz.lovegu.server.sys.service.UserService;
import xyz.lovegu.server.sys.vos.UserVo;

/**
 * @author 老顾
 * @title: UserController
 * @projectName campus-prevention-system
 * @email: 1437594522@qq.com
 * @date 2022/5/4 23:42
 */
@Validated
@RestController
@RequestMapping("sys/user")
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    @PostMapping("addStudent")
    public ResultMessage<ResultObj> addStudent(@RequestBody UserVo userVo) {
        return ResultUtil.data(userService.addStudent(userVo));
    }

    @PostMapping("addTeacher")
    public ResultMessage<ResultObj> addTeacher(@RequestBody UserVo userVo) {
        return ResultUtil.data(userService.addTeacher(userVo));
    }
    @PostMapping("delUserById")
    public ResultMessage<ResultObj> delUserById(@RequestBody UserVo userVo) {
        return ResultUtil.data(userService.delUserById(userVo));
    }

    @PostMapping("updateUserInfo")
    public ResultMessage<ResultObj> updateUserInfo(@RequestBody UserVo userVo) {
        return ResultUtil.data(userService.updateUserInfo(userVo));
    }

    @PostMapping("resetUserPassword/{id}")
    public ResultMessage<ResultObj> resetUserPassword(@RequestBody UserVo userVo) {
        return ResultUtil.data(userService.resetUserPassword(userVo));
    }

    @PostMapping("updateUserPassword")
    public ResultMessage<ResultObj> updateUserPassword(@RequestBody UserVo userVo) {
        return ResultUtil.data(userService.updateUserPassword(userVo));
    }

    @GetMapping("getUserById")
    public ResultMessage<Object> getUserById(@RequestParam("id") Integer id) {
        return ResultUtil.data(userService.getUserById(id));
    }

    @GetMapping("getClassIdByStudent")
    public ResultMessage<Object> getClassIdByStudent(@RequestParam("classId") Integer classId) {
        return ResultUtil.data(userService.getClassIdByStudent(classId));
    }

    @GetMapping("getClassIdByTeacher")
    public ResultMessage<Object> getClassIdByTeacher(@RequestParam("classId") Integer classId) {
        return ResultUtil.data(userService.getClassIdByTeacher(classId));
    }

    @GetMapping("getAllUsers")
    public ResultMessage<DataGridView> getAllUsers(UserVo userVo) {
        return ResultUtil.data(userService.getAllUsers(userVo));
    }
}
